1 /* 2 Copyright: Marcelo S. N. Mancini (Hipreme|MrcSnm), 2018 - 2021 3 License: [https://creativecommons.org/licenses/by/4.0/|CC BY-4.0 License]. 4 Authors: Marcelo S. N. Mancini 5 6 Copyright Marcelo S. N. Mancini 2018 - 2021. 7 Distributed under the CC BY-4.0 License. 8 (See accompanying file LICENSE.txt or copy at 9 https://creativecommons.org/licenses/by/4.0/ 10 */ 11 module hip.hiprenderer.framebuffer; 12 import hip.hiprenderer.shader; 13 import hip.hiprenderer.renderer; 14 import hip.api.renderer.texture; 15 16 17 18 interface IHipFrameBuffer 19 { 20 ///Creates the framebuffer using the target width and height 21 void create(uint width, uint height); 22 23 ///Resizes the framebuffer, probably this will not be implemented in the backend level 24 void resize(uint width, uint height); 25 26 ///Binds the framebuffer, setting it as a target for every draw call 27 void bind(); 28 ///Unbinds the framebuffer, resetting the renderer state and setting the output as the screen 29 void unbind(); 30 ///Must draw the framebuffer content 31 void draw(); 32 33 ///Clears the current framebuffer content 34 void clear(); 35 36 ///Gets the texture containing the framebuffer data 37 IHipTexture getTexture(); 38 39 void dispose(); 40 } 41 42 class HipFrameBuffer : IHipFrameBuffer 43 { 44 Shader currentShader; 45 protected IHipFrameBuffer impl; 46 int width, height; 47 this(IHipFrameBuffer fbImpl, int width, int height, Shader framebufferShader = null) 48 { 49 impl = fbImpl; 50 this.width = width; 51 this.height = height; 52 if(framebufferShader is null) 53 currentShader = HipRenderer.newShader(HipShaderPresets.FRAME_BUFFER); 54 } 55 void create(uint width, uint height){} 56 void resize(uint width, uint height){} 57 58 void bind() 59 { 60 this.impl.bind(); 61 } 62 void unbind() 63 { 64 this.impl.unbind(); 65 } 66 void clear() 67 { 68 this.impl.clear(); 69 } 70 IHipTexture getTexture(){return impl.getTexture();} 71 72 void draw() 73 { 74 currentShader.bind(); 75 impl.draw(); 76 } 77 78 void dispose(){impl.dispose();} 79 80 } 81 82 83 package const float[24] framebufferVertices = //X, Y, S, T 84 [ 85 //First Quad 86 //Top Left 87 -1.0, -1.0, 0.0, 0.0, 88 89 //Top Right 90 1.0, -1.0, 1.0, 0.0, 91 92 //Bot Right 93 1.0, 1.0, 1.0, 1.0, 94 95 //Second quad 96 97 //Bot Right 98 1.0, 1.0, 1.0, 1.0, 99 100 //Bot Left 101 -1.0, 1.0, 0.0, 1.0, 102 103 //Top Left 104 -1.0, -1.0, 0.0, 0.0 105 ];